package com.link.base.base.approval.controller;

import com.link.base.base.approval.model.Approval;
import com.link.base.base.approval.service.ApprovalService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.BasicServiceException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * Copyright  hande Company. All Rights Reserved.
 *
 * @author  unknwon
 * @date:   2018/11/8 14:26
 * @version 1.0
 */

@Controller
@RequestMapping("/link/approval")
public class ApprovalController extends BasicController<Approval> {
    @Resource
    private ApprovalService approvalService;

    @Override
    public BasicService<Approval> getBasicService() throws Exception {
        return approvalService;
    }


    /**
    * 审批流程更新，同时根据审批流的flowJson字段更新审批节点信息
    * @author Lizongting
    * @date 2020/6/10
    */
    @RequestMapping({"/subdataUpdate"})
    @ResponseBody
    public Map<String, Object> subdataUpdate(@JsonParam Approval entity, HttpSession session,
                                             HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<>(4);

        try {
            if (!this.checkExistDataCache("base", session, entity)) {
                throw new BasicServiceException("非法更新数据！");
            }
            approvalService.subdataUpdate(entity);
            result.put("newRow", entity);
            result.put("success", true);
            result.put("code", "200");
        } catch (BasicServiceException var7) {
            result.put("success", false);
            result.put("result", var7.getMessage());
            result.put("detailMessage", var7.getDetailMessage());
            result.put("code", var7.getCode());
        } catch (Exception var8) {
            result.put("success", false);
            result.put("result", var8.getMessage());
            result.put("code", "400");
        }

        return result;
    }
}
